package cn.kgc.crowdfundingadmin.service;

import cn.kgc.crowdfundingadmin.common.CrowdFundingUtils;
import cn.kgc.crowdfundingadmin.mapper.AuthMapper;
import cn.kgc.crowdfundingadmin.pojo.Auth;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author shkstart
 * @create 2020-03-03 16:24
 */
@Service("authService")
public class AuthServiceImpl implements  AuthService {

    @Resource
    AuthMapper authMapper;
    @Override
    public List<Auth> getAllAuth() {
        return authMapper.selectByExample(null);
    }

    @Override
    public List<Integer> getAssignedAuthIdList(Integer roleId) {
        return authMapper.getAssignedAuthIdList(roleId);
    }

    @Override
    public void updateRelationShipBetweenRoleAndAuth(Map<String, List<Integer>> assignDataMap) {
        //获取俩部分list的数据
        List<Integer>    roleIdList=assignDataMap.get("roleIdList");
        List<Integer>    authIdList =assignDataMap.get("authIdList");
        ///取出roleId
        Integer roleId=roleIdList.get(0);
    //删除旧的
        authMapper.deleteRelationship(roleId);
        //保存新的
        if(CrowdFundingUtils.collectionEffective(authIdList)){
            authMapper.insertRelationship(roleId,authIdList);
        }

    }
}
